package com.tougutips.modules.user.followers.config;

import com.tougutips.modules.user.followers.task.FollowTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author:HuangYiF
 * @create: 2022-07-27 17:14
 * @Description:
 */
@Configuration
public class QuartzConfig {

    private static final String FOLLOW_TASK_IDENTITY = "FollowTaskQuartz";

    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(FollowTask.class).withIdentity(FOLLOW_TASK_IDENTITY).storeDurably().build();
    }

    @Bean
    public Trigger quartzTrigger(){
        //两个小时执行一次
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInHours(2)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail())
                .withIdentity(FOLLOW_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)
                .build();
    }
}